package com.tiantian.user.dubbo;

import cn.hutool.core.bean.BeanUtil;
import com.tiantian.api.RemoteUserService;
import com.tiantian.api.domain.vo.RemoteUserVo;
import com.tiantian.user.domain.entity.SysUser;
import com.tiantian.user.service.SysUserService;
import lombok.RequiredArgsConstructor;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author tiantian
 */
@RequiredArgsConstructor
@Service
@DubboService
public class RemoteUserServiceImpl implements RemoteUserService {

    private final SysUserService sysUserService;

    @Override
    public int getUserTotalScoreById(Long userId) {
        SysUser sysUser = sysUserService.selectUserById(userId);
        return sysUser.getTotalScore();
    }

    @Override
    public int getNewcomerCount() {
        return sysUserService.countNewcomer();
    }

    @Override
    public List<RemoteUserVo> getStaffs() {
        List<SysUser> sysUsers = sysUserService.selectCandidate();
        return BeanUtil.copyToList(sysUsers, RemoteUserVo.class);
    }

    @Override
    public RemoteUserVo getUserById(Long userId) {
        SysUser sysUser = sysUserService.selectUserById(userId);
        return BeanUtil.copyProperties(sysUser, RemoteUserVo.class);
    }

    @Override
    public String getUserNickNameById(Long userId) {
        return sysUserService.selectUserNameById(userId);
    }

    @Override
    public int setNewcomerTotalScore(Long replyUserId, int totalScore) {
        return sysUserService.setNewcomerTotalScore(replyUserId, totalScore);
    }

    @Override
    public List<RemoteUserVo> getNewcomerList(RemoteUserVo queryParams) {
        SysUser param = BeanUtil.copyProperties(queryParams, SysUser.class);
        List<SysUser> sysUsers = sysUserService.selectNewcomerList(param);
        return BeanUtil.copyToList(sysUsers, RemoteUserVo.class);
    }

    @Override
    public boolean updateUserAvatar(Long userId, String avatarURL) {
        return sysUserService.updateUserAvatar(userId, avatarURL) > 0;
    }
}
